#ifndef STRUCT_WRAPPER_H
#define STRUCT_WRAPPER_H
#include "rose.h"
#include <sstream>
#include "FunctionContext.h"
#include "VariableWrapper.h"

using namespace std;

class StructWrapper {
    public:
        StructWrapper(SgClassDefinition *set_def) { def = set_def; fields = NULL; n_fields = 0; }
        SgClassDefinition *get_def() { return def; }
        void addField(SgVariableDeclaration *var) { 
            SgInitializedNamePtrList& list = var->get_variables();
            for(unsigned int i = 0; i < list.size(); i++) {
                fields = (VariableWrapper **)realloc(fields, sizeof(VariableWrapper *) * (n_fields+1));
                fields[n_fields] = new VariableWrapper(list[i], var, NULL);
                n_fields++;
            }
        }
        string get_name() { return def->get_declaration()->get_name().str(); }
        string str() {
            stringstream ss;
            ss<<"struct "<<get_name()<<" {"<<endl;
            for(int i = 0; i < n_fields; i++) {
                ss<<"    "<<fields[i]->get_name()->get_name().str()<<";"<<endl;
            }
            ss<<"};"<<endl;
            return ss.str();
        }

    private:
        SgClassDefinition *def;
        VariableWrapper **fields;
        int n_fields;
};

#endif
